package edu.washington.ling.syntric.io;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class ExampleDoc {
	private Map<String, Example> exampleMap;
	private Iterator<Example> exampleIterator;
	
	public ExampleDoc() {
		exampleMap = new HashMap<String, Example>();
		exampleIterator = exampleMap.values().iterator();
	}
	public boolean hasExample(String id) {
		return exampleMap.containsKey(id);
	}
	public void addExample(Example ex) {
		exampleMap.put(ex.getID(), ex);
	}
	public void resetIterator() {
		exampleIterator = exampleMap.values().iterator();
	}
	public int numExamples() {
		return exampleMap.size();
	}
	public Set<String> getIDs() {
		return exampleMap.keySet();
	}
	public Example getNextExample() {
		Example ex = null;
		if (exampleIterator.hasNext()) {
			ex = exampleIterator.next();
		}
		return ex;
	}
	public boolean hasExampleWithID(String id) {
		return exampleMap.containsKey(id);
	}
	public Example getExampleWithID(String id) {
		Example ex = null;
		if (exampleMap.containsKey(id)) {
			ex = exampleMap.get(id);
		}
		return ex;
	}

}
